﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace WRJ
{
	public partial class Index : BaseForm
	{
		/// <summary>
		/// 登录的模式
		/// Mode=0 为教学和训练模式
		/// Mode=1 为考核模式
		/// </summary>
		public static int Mode;
		/// <summary>
		/// 登录界面的窗体
		/// </summary>
		private Login login;
		/// <summary>
		/// 中间的控件所占的比例，范围0-1
		/// </summary>
		public static double CenterPercent = 0.625;
		/// <summary>
		/// 两侧的控件所占的比例，范围0-1
		/// </summary>
		public static double SidePercent = (1 - CenterPercent) / 2;
		/// <summary>
		/// 右侧上方的RichTextBox所占整个高度的比例，范围0-1
		/// </summary>
		public static double RightSidePercent = 0.6;
		/// <summary>
		/// 整个控件的宽度，单位：像素
		/// </summary>
		public static int ControlWidth;
		/// <summary>
		/// 整个控件的高度，单位：像素
		/// </summary>
		public static int ControlHeight;

		public Index(int mode, Login lg)
		{
			InitializeComponent();
			this.FormClosing += new FormClosingEventHandler(Index_FormClosing);
			login = lg;
			Mode = mode;
			SetMainControl();
			BaseCommonClass.SetFont(MainControl);
			BaseCommonClass.SetFont(装备认知_树状结构);
			装备认知_树状结构.SelectedNode = 装备认知_树状结构.TopNode;
			ControlWidth = SystemInformation.PrimaryMonitorSize.Width - SystemInformation.Border3DSize.Width * 2;
			ControlHeight = SystemInformation.PrimaryMonitorSize.Height - SystemInformation.CaptionHeight;
			this.MainControl.Size = new Size(Convert.ToInt32(ControlWidth * SidePercent), ControlHeight);
		}

		void Index_FormClosing(object sender, FormClosingEventArgs e)
		{
			DialogResult result = MessageBox.Show("确定要退出该系统吗？", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
			if (result == DialogResult.OK)
			{
				e.Cancel = false;
				login.Close();
				Application.Exit();
			}
			else
			{
				e.Cancel = true;
			}
		}

		private void SetMainControl()
		{
			if (Mode == 0)
			{
				TabPage tp = MainControl.TabPages[2];
				MainControl.TabPages.Remove(tp);
			}
			else if (Mode == 1)
			{
				TabPage tp = MainControl.TabPages[0];
				MainControl.TabPages.Remove(tp);
				tp = MainControl.TabPages[0];
				MainControl.TabPages.Remove(tp);
			}
		}


		/// <summary>
		/// 主要的判断逻辑
		/// 根据树状结构里面的名称，判断需要载入的用户控件
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void 装备认知_树状结构_DoubleClick(object sender, EventArgs e)
		{
			TreeView treeView = (TreeView)sender;
			if (treeView.SelectedNode == null) return;

			switch (treeView.SelectedNode.Name)
			{
				case "机身":
					var collection = this.Controls.OfType<UserControl>();
					foreach (var item in collection)
					{
						item.Dispose();
					}
					var userControl = new JiShen();
					//userControl.Location = new System.Drawing.Point(Convert.ToInt32(ControlWidth * SidePercent), 0);
					userControl.Location = new System.Drawing.Point(239, 0);
					this.Controls.Add(userControl);
					break;
				default:
					if (treeView.SelectedNode.Parent != null)
						MessageBox.Show("无法找到已选中的用户控件：" + treeView.SelectedNode.Name, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
					break;
			}
		}


	}
}
